# -*- coding: utf-8 -*-
# @Time : 2023/11/21 20:58
# @Author : 支晓光3
# @Email : 1473858993@qq.com
# @File : logg_utils.py
# @Project : YouGuuUII
import logging
import os.path

from common.handler_path import logs_dir


class LogUtil:

    def __init__(self, fname):
        # 获取一个logger对象
        logger = logging.getLogger()
        # 总日志级别
        logger.setLevel(logging.INFO)
        # 日志存放位置
        filepath = os.path.join(logs_dir, fname)
        # 文件处理器handler
        handler = logging.FileHandler(filepath, mode='a+', encoding='utf8')
        # 格式器
        fromatter = logging.Formatter(
            '%(levelname)s %(filename)s %(asctime)s %(message)s %(lineno)d ')
        # 设置日志输出格式
        handler.setFormatter(fromatter)
        # 添加handler
        logger.addHandler(handler)